//
//  ClientRequest.m
//  MobileOffice
//
//  Created by jjkj on 17/3/1.
//  Copyright © 2017年 liaoningjujin. All rights reserved.
//

#import "ClientRequest.h"
#import "HttpRequest.h"
@implementation ClientRequest
+ (void)SOAPMthod:(NSString *)soapMthod soapBody:(NSDictionary *)parames
         success:(void (^)(id responseObject))success failure:(void(^)(NSError *error))failure
{
    
    //   字典转json
    NSString* str = @"";
    if ([DataCheck isValidDictionary:parames]) {
        NSData* jsonData = [NSJSONSerialization dataWithJSONObject:parames options:NSJSONWritingPrettyPrinted error:nil];
         str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
       //拼接soap字符串
    NSString * soap = @"";
    soap = [NSString stringWithFormat:@"<funcName>%@</funcName>\n<content>%@</content>",soapMthod,str];
    [HttpRequest SOAPData:[CommClass getServerURL] SoapMthod:soapMthod soapBody:soap success:^(id responseObject) {
        NSInteger code =[[responseObject objectForKey:@"code"] integerValue];

            if (success) {
                success([responseObject objectForKey:@"retContent"]);
            }
        if(code == 220) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [MBProgressHUD hideLoadViewWithView:kWindow];
                if ([DataCheck isValidString:responseObject[@"msg"]]) {
                     [MBProgressHUD postMessageWithText:[responseObject objectForKey:@"msg"] View:kWindow];
                }
            });
            return;
        }
        
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];

}
@end
